fgets and strcmp [C]
Posted
by Blackbinary
on Stack Overflow
See other posts from Stack Overflow
or by Blackbinary
Published on 2010-03-08T21:13:44Z
Indexed on
2010/03/08
21:21 UTC
Read the original article
Hit count: 428
I'm trying to compare two strings. One stored in a file, the other retrieved from the user (stdin).
Here is a sample program:
int main()
{
char targetName[50];
fgets(targetName,50,stdin);
char aName[] = "bob";
printf("%d",strcmp(aName,targetName));
return 0;
}
In this program, strcmp returns a value of -1 when the input is 'bob'. Why is this? I thought they should be equal. How can i get it so that they are?
© Stack Overflow or respective owner